﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ProtetoresDaMata.Objects;
using Microsoft.Xna.Framework;
using ProtetoresDaMata.Smarts;

namespace ProtetoresDaMata.Physics
{
    public class PhysicsBase
    {

        public bool action;
        public bool jump;
        public bool doubleJump;


        public float gravity
        {
            get
            {
                return 520f;
            }
        }

        public double velocityInitial { get; set; }
        public double time { get; set; }


        public PhysicsBase()
        {

        }

        public void Jump(Sprite character, GameTimerEventArgs gameTime)
        {
            if (action)
            {
                // the normal formula is: vi * t - g * t^2 / 2 and vi is positive, but here UP means decrease Y and DOWN means increase Y
                // that's why it looks strange
                character.Position.Y = (float)(velocityInitial * time + gravity * time * time * 2) + 245;
                time = time + gameTime.ElapsedTime.TotalSeconds; // calculate the time since the ball has left the ground
            }

            if (character.Position.Y > 245) // Don't allow the ball to go beyond the bottom side of the window
            {
                character.Position.Y = 245;
                time = 0;

                action = false;
            }
        }

        public void InitiJump(Sprite character, GameTimerEventArgs timeEvents)
        {
            if (jump && !this.action)
            {
                ActionsOfJump(-900,ref jump);
            }

            if (this.doubleJump && !this.action)
            {
                ActionsOfJump(-1050,ref doubleJump);
            }

            if (action)
            {
                this.Jump(character, timeEvents);
            }

        }

        private void ActionsOfJump(int velocity, ref bool actionEvent)
        {
            this.velocityInitial = velocity;
            this.action = true;
            actionEvent = false;
        }




    }
}
